package cn.ibdsr.human.controller;

import cn.ibdsr.human.constant.Const;
import cn.ibdsr.human.constant.Result;
import cn.ibdsr.human.service.AdInforService;
import cn.ibdsr.human.transfer.ad.AdInforDTO;
import cn.ibdsr.human.transfer.company.CompanyResponseDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: cdl
 * @email: iamcimon@qq.com
 * @date: 2021/8/5 10:04
 */
@Api(tags = "轮播图控制器")
@RestController
@RequestMapping(value = "/ads")
@Slf4j
@Validated
public class AdInfoController {

    @Resource
    private AdInforService adInforService;
    /**
     * cdl-oko
     * 获取个人信息
     */
    @ApiOperation("获取轮播图列表")
    @GetMapping
    @ResponseBody//
    public Result<List<AdInforDTO>> list() {
        // Long userId=1L;
        List<AdInforDTO> adInforDTOS=adInforService.list( );
        return new Result<>(adInforDTOS);
    }
    /**
     * cdl-ok
     * 获取个人信息
     */
    @ApiOperation("保存图片位置")
    @PutMapping
    @ResponseBody//
    public Result<Boolean> savePostion(@RequestAttribute(name = Const.USER_ID  ) Long userId,@RequestBody  List<AdInforDTO> adInforDTOS) {
        // Long userId=1L;
        Boolean flag=adInforService.savePostion(userId,adInforDTOS );
        return new Result<>(flag);
    }
    /**
     * cdl-ok
     * 获取个人信息
     */
    @ApiOperation("删除图片")
    @DeleteMapping("/{id}")
    @ResponseBody//
    public Result<Long> delete(@RequestAttribute(name = Const.USER_ID  ) Long userId,@PathVariable("id") Long id) {
        // Long userId=1L;
        Long flag=adInforService.delete(userId,id );
        return new Result<>(flag);
    }
    /**
     * cdl-ok
     * 获取个人信息
     */
    @ApiOperation("增加轮播图")
    @PostMapping
    @ResponseBody//
    public Result<Long> add(@RequestAttribute(name = Const.USER_ID  ) Long userId,@RequestBody AdInforDTO adInforDTO) {
        // Long userId=1L;
        Long flag=adInforService.add(userId,adInforDTO );
        return new Result<>(flag);
    }

}
